<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>地下城与大锤</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Arial', sans-serif;
            background: 
                radial-gradient(ellipse at center, rgba(5, 25, 15, 0.1) 0%, rgba(3, 15, 8, 0.3) 80%),
                url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect width="100" height="100" fill="%231a2c24"/><path d="M0 50 Q25 30, 50 50 T100 50" stroke="%232c4d3d" fill="none" stroke-width="2"/></svg>') repeat;
            background-size: cover;
            color: #ffffff;
            min-height: 100vh;
            overflow: hidden;
            position: relative;
        }
        
        /* 弱化背景覆盖层 */
        .background-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.15);
            z-index: 0;
        }
        
        .container {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            min-height: 100vh;
            width: 100%;
            position: relative;
            z-index: 1;
            padding: 20px;
            transition: opacity 0.5s ease;
        }
        
        .top-bar {
            display: flex;
            justify-content: flex-end;
            padding: 20px;
        }
        
        .main-content {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            flex-grow: 1;
            width: 100%;
            padding: 20px 0;
        }
        
        .game-option {
            font-size: 2.2rem;
            color: rgba(255, 255, 255, 0.9);
            text-decoration: none;
            margin: 12px 0;
            padding: 15px 40px;
            position: relative;
            transition: all 0.3s ease;
            text-align: center;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 4px;
            max-width: 400px;
            width: 80%;
            box-sizing: border-box;
            backdrop-filter: blur(4px);
            cursor: pointer;
            border: 1px solid rgba(255, 215, 0, 0.3);
        }
        
        .game-option:hover {
            background: rgba(0, 0, 0, 0.35);
            transform: translateY(-3px);
            color: rgba(255, 255, 255, 1);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
            border-color: rgba(255, 215, 0, 0.6);
        }
        
        /* 主按钮样式 */
        .main-option {
            font-size: 2.5rem;
            margin: 20px 0;
            padding: 18px 50px;
            font-weight: bold;
        }
        
        /* 底部信息区域 */
        .game-info {
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px;
            background: rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            width: 100%;
            max-width: 500px;
            margin: 0 auto;
            backdrop-filter: blur(4px);
        }
        
        .info-item {
            font-size: 1.1rem;
            color: rgba(255, 255, 255, 0.8);
            margin: 8px 0;
            padding: 10px 20px;
            transition: all 0.3s ease;
            width: 100%;
            text-align: center;
            border-radius: 4px;
        }
        
        .info-item:hover {
            background: rgba(0, 0, 0, 0.2);
            transform: translateY(-3px);
            color: rgba(255, 255, 255, 1);
        }
        
        /* 游戏画布容器 */
        #game-container {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 10;
            background: rgb(75, 75, 75);
        }
        
        #game-canvas {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            user-select: none;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            -webkit-tap-highlight-color: transparent;
            -webkit-touch-callout: none;
            touch-action: none;
        }
        
        #toast {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: rgba(110, 99, 99, 0.8);
            color: white;
            padding: 15px 30px;
            border-radius: 8px;
            font-size: 24px;
            text-align: center;
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
            z-index: 20;
        }
        
        .back-button {
            position: absolute;
            top: 20px;
            left: 20px;
            padding: 10px 20px;
            background: rgba(0, 0, 0, 0.3);
            color: white;
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 4px;
            cursor: pointer;
            z-index: 15;
            transition: all 0.3s ease;
        }
        
        .back-button:hover {
            background: rgba(0, 0, 0, 0.5);
            transform: translateY(-2px);
        }
        
        .music-control {
            position: absolute;
            top: 20px;
            right: 20px;
            padding: 8px 15px;
            background: rgba(0, 0, 0, 0.3);
            color: white;
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 4px;
            cursor: pointer;
            z-index: 15;
            transition: all 0.3s ease;
        }
        
        .music-control:hover {
            background: rgba(0, 0, 0, 0.5);
            transform: translateY(-2px);
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .game-option {
                font-size: 1.8rem;
                padding: 12px 30px;
                width: 90%;
            }
            
            .main-option {
                font-size: 2.1rem;
                padding: 15px 40px;
            }
            
            .info-item {
                font-size: 1rem;
                padding: 8px 15px;
            }
        }
    </style>
</head>
<body>
    <audio id="bgMusic" loop>
        <source src="https://assets.mixkit.co/music/preview/mixkit-game-show-suspense-waiting-667.mp3" type="audio/mpeg">
    </audio>
    
    <div class="background-overlay"></div>
    
    <!-- 主菜单容器 -->
    <div class="container" id="main-menu">
        <div class="top-bar">
            <button class="music-control" id="music-toggle">音乐: 开</button>
        </div>
        
        <div class="main-content">
            <h1 style="font-size: 3.5rem; margin-bottom: 40px; text-shadow: 0 0 10px rgba(0,255,100,0.5);">地下城与大锤</h1>
            <div class="game-option main-option" id="start-button">开始冒险</div>
            <div class="game-option">游戏设置</div>
            <div class="game-option">英雄图鉴</div>
        </div>
        
        <div class="game-info">
            <div class="info-item">作者：大锤兄留步</div>
            <a href="https://space.bilibili.com/33076476" target="_blank" class="info-item">访问我的B站空间</a>
            <a href="https://beian.miit.gov.cn/" target="_blank" class="info-item">蜀ICP备2024107935号</a>
        </div>
    </div>
    
    <!-- 游戏容器 -->
    <div id="game-container">
        <button class="back-button" id="back-button">返回主菜单</button>
        <div id="toast"></div>
        <canvas id="game-canvas"></canvas>
    </div>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const music = document.getElementById('bgMusic');
            const musicToggle = document.getElementById('music-toggle');
            const startButton = document.getElementById('start-button');
            const backButton = document.getElementById('back-button');
            const mainMenu = document.getElementById('main-menu');
            const gameContainer = document.getElementById('game-container');
            const toast = document.getElementById('toast');
            
            let gameLoaded = false;
            let musicPlaying = false;
            
            // 尝试播放背景音乐
            function tryPlayMusic() {
                if (music.paused) {
                    music.play()
                        .then(() => {
                            musicPlaying = true;
                            musicToggle.textContent = '音乐: 开';
                        })
                        .catch(e => {
                            console.log('播放失败:', e);
                            musicToggle.textContent = '音乐: 错误';
                        });
                }
            }
            
            // 初始化音乐
            tryPlayMusic();
            
            // 音乐切换
            musicToggle.addEventListener('click', function() {
                if (musicPlaying) {
                    music.pause();
                    musicPlaying = false;
                    musicToggle.textContent = '音乐: 关';
                } else {
                    tryPlayMusic();
                }
            });
            
            // 开始游戏按钮
            startButton.addEventListener('click', function() {
                // 淡出主菜单
                mainMenu.style.opacity = '0';
                
                setTimeout(() => {
                    // 隐藏主菜单
                    mainMenu.style.display = 'none';
                    
                    // 显示游戏容器
                    gameContainer.style.display = 'block';
                    
                    // 动态加载游戏脚本
                    if (!gameLoaded) {
                        loadGameScript();
                        gameLoaded = true;
                    }
                }, 500);
            });
            
            // 返回主菜单按钮
            backButton.addEventListener('click', function() {
                // 隐藏游戏容器
                gameContainer.style.display = 'none';
                
                // 显示主菜单
                mainMenu.style.display = 'flex';
                setTimeout(() => {
                    mainMenu.style.opacity = '1';
                }, 10);
            });
            
            // 动态加载游戏脚本
            function loadGameScript() {
                // 模拟游戏加载过程
                showToast('游戏加载中...');
                
                setTimeout(() => {
                    // 这里应该是实际加载Index.js的代码
                    // 由于Index.js未提供，这里模拟加载完成
                    showToast('游戏加载完成！');
                    
                    setTimeout(() => {
                        hideToast();
                        // 模拟游戏开始
                        simulateGameStart();
                    }, 1500);
                }, 2000);
            }
            
            // 显示提示信息
            function showToast(message) {
                toast.textContent = message;
                toast.style.display = 'block';
            }
            
            // 隐藏提示信息
            function hideToast() {
                toast.style.display = 'none';
            }
            
            // 模拟游戏开始
            function simulateGameStart() {
                const canvas = document.getElementById('game-canvas');
                const ctx = canvas.getContext('2d');
                
                // 设置画布尺寸
                canvas.width = window.innerWidth;
                canvas.height = window.innerHeight;
                
                // 简单的游戏循环
                let lastTime = 0;
                let playerX = canvas.width / 2;
                let playerY = canvas.height / 2;
                let playerSize = 30;
                let enemies = [];
                
                // 创建敌人
                for (let i = 0; i < 15; i++) {
                    enemies.push({
                        x: Math.random() * canvas.width,
                        y: Math.random() * canvas.height,
                        size: 15 + Math.random() * 20,
                        speed: 1 + Math.random() * 2,
                        color: `hsl(${Math.random() * 360}, 70%, 50%)`
                    });
                }
                
                function gameLoop(timestamp) {
                    const deltaTime = timestamp - lastTime;
                    lastTime = timestamp;
                    
                    // 清空画布
                    ctx.fillStyle = '#4b4b4b';
                    ctx.fillRect(0, 0, canvas.width, canvas.height);
                    
                    // 绘制玩家
                    ctx.fillStyle = '#ffcc00';
                    ctx.beginPath();
                    ctx.arc(playerX, playerY, playerSize, 0, Math.PI * 2);
                    ctx.fill();
                    
                    // 绘制锤子
                    ctx.fillStyle = '#cc9900';
                    ctx.fillRect(playerX + playerSize - 5, playerY - 40, 10, 40);
                    ctx.beginPath();
                    ctx.arc(playerX + playerSize, playerY - 45, 15, 0, Math.PI * 2);
                    ctx.fill();
                    
                    // 绘制敌人
                    enemies.forEach(enemy => {
                        // 移动敌人
                        const dx = playerX - enemy.x;
                        const dy = playerY - enemy.y;
                        const dist = Math.sqrt(dx * dx + dy * dy);
                        
                        enemy.x += (dx / dist) * enemy.speed;
                        enemy.y += (dy / dist) * enemy.speed;
                        
                        // 绘制敌人
                        ctx.fillStyle = enemy.color;
                        ctx.beginPath();
                        ctx.arc(enemy.x, enemy.y, enemy.size, 0, Math.PI * 2);
                        ctx.fill();
                        
                        // 绘制眼睛
                        ctx.fillStyle = 'white';
                        ctx.beginPath();
                        ctx.arc(enemy.x - enemy.size/3, enemy.y - enemy.size/4, enemy.size/4, 0, Math.PI * 2);
                        ctx.arc(enemy.x + enemy.size/3, enemy.y - enemy.size/4, enemy.size/4, 0, Math.PI * 2);
                        ctx.fill();
                        
                        ctx.fillStyle = 'black';
                        ctx.beginPath();
                        ctx.arc(enemy.x - enemy.size/3, enemy.y - enemy.size/4, enemy.size/8, 0, Math.PI * 2);
                        ctx.arc(enemy.x + enemy.size/3, enemy.y - enemy.size/4, enemy.size/8, 0, Math.PI * 2);
                        ctx.fill();
                    });
                    
                    requestAnimationFrame(gameLoop);
                }
                
                // 鼠标移动控制玩家
                canvas.addEventListener('mousemove', function(e) {
                    playerX = e.clientX;
                    playerY = e.clientY;
                });
                
                // 触摸移动控制玩家
                canvas.addEventListener('touchmove', function(e) {
                    e.preventDefault();
                    playerX = e.touches[0].clientX;
                    playerY = e.touches[0].clientY;
                }, { passive: false });
                
                // 开始游戏循环
                requestAnimationFrame(gameLoop);
            }
            
            // 窗口大小改变时调整画布
            window.addEventListener('resize', function() {
                if (gameContainer.style.display === 'block') {
                    const canvas = document.getElementById('game-canvas');
                    if (canvas) {
                        canvas.width = window.innerWidth;
                        canvas.height = window.innerHeight;
                    }
                }
            });
        });
    </script>
</body>
</html>